package org.gruposp2p.dnie.client.ui.dialogs;

import org.gruposp2p.dnie.client.dto.DocumentToSignOptionDTO;
import org.gruposp2p.dnie.client.event.EventBusManager;
import org.gruposp2p.dnie.client.event.OptionChangeEvent;
import org.gruposp2p.dnie.client.ui.panel.MainPanel;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;

public class ConfirmDeleteOptionDialog extends DialogBox {
	
    public static final String TEXT_WIDGET_WIDTH = "350";

    public DocumentToSignOptionDTO option;

    public ConfirmDeleteOptionDialog (DocumentToSignOptionDTO option) {
        setText(MainPanel.constants.confirmDeleteOptionPanelCaption());
        ensureDebugId("CreateOptionDialog");
        this.option = option;
        showDialog();
    }

    private void showDialog () {
        FlexTable layout = new FlexTable();
        layout.clear();
        layout.setCellSpacing(5);
        VerticalPanel vPanel = new VerticalPanel();
        vPanel.add(new HTML(MainPanel.constants.confirmDeleteOptionMessage()));
        layout.setWidget(0,0,vPanel);
        Button cancelButton = new Button(
            MainPanel.constants.cancelButtonText(),
            new ClickHandler() {
                public void onClick(ClickEvent event) {
                hide();
            }
        });

        Button acceptButton = new Button(
        MainPanel.constants.acceptButtonText(),
        new ClickHandler() {
            public void onClick(ClickEvent event) {
                OptionChangeEvent optionChangeEvent =
                    new OptionChangeEvent(option, OptionChangeEvent.OPTION_DELETED);
                EventBusManager.getInstance().fireEvent(optionChangeEvent);
                hide();
            }
        });

        HorizontalPanel hPanel = new HorizontalPanel();
        hPanel.setSpacing(5);
        hPanel.add(acceptButton);
        hPanel.add(cancelButton);
        layout.setWidget(1, 0, hPanel);
        CellFormatter cellFormatter = layout.getCellFormatter();
        cellFormatter.setHorizontalAlignment(1, 0, HorizontalPanel.ALIGN_RIGHT);
        setWidget(layout);
        this.show();
    }

}